home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / amiga / asrc29k.lha / timer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  1.8 KB  |  55 lines

  1. #ifndef    TIMER_STOP
  2.  
  3. #include "global.h"
  4.  
  5. /* Software timers
  6.  * There is one of these structures for each simulated timer.
  7.  * Whenever the timer is running, it is on a doubly-linked list
  8.  * pointed to by "Timers". The list is sorted in ascending order of
  9.  * expiration, with the next timer to expire at the head. Each timer's
  10.  * count field contains only the additional INCREMENT over all preceeding
  11.  * timers; this allows the hardware timer interrupt to decrement only the
  12.  * first timer on the chain until it hits zero.
  13.  *
  14.  * Stopping a timer or letting it expire causes it to be removed
  15.  * from the list. Starting a timer puts it on the list at the right
  16.  * place. These operations have to be careful about adjusting the count
  17.  * field of the next entry in the list.
  18.  */
  19. struct timer {
  20.     struct timer *next;    /* Doubly-linked-list pointers */
  21.     struct timer *prev;
  22.     int32 start;        /* Period of counter (load value) */
  23.     int32 count;        /* Ticks to go until expiration */
  24.     void (*func) __ARGS((void *));    /* Function to call at expiration */
  25.     void *arg;        /* Arg to pass function */
  26.     char state;        /* Timer state */
  27. #define    TIMER_STOP    0
  28. #define    TIMER_RUN    1
  29. #define    TIMER_EXPIRE    2
  30. };
  31. #define    NULLTIMER    (struct timer *)0
  32. #define    MAX_TIME    (int32)4294967295    /* Max long integer */
  33. #ifndef    MSPTICK
  34. #define    MSPTICK        55        /* Milliseconds per tick */
  35. #endif
  36. /* Useful user macros that hide the timer structure internals */
  37. #define    set_timer(t,x)    (((t)->start) = (x)/MSPTICK)
  38. #define    dur_timer(t)    ((t)->start)
  39. #define    run_timer(t)    ((t)->state == TIMER_RUN)
  40.  
  41. extern int32 Clock;    /* Count of ticks since start up */
  42. extern int Tick;
  43.  
  44. /* In timer.c: */
  45. void alarm __ARGS((int32 ticks));
  46. int pause __ARGS((int32 ticks));
  47. int32 read_timer __ARGS((struct timer *t));
  48. void start_timer __ARGS((struct timer *t));
  49. void stop_timer __ARGS((struct timer *t));
  50. char *tformat __ARGS((int32 t));
  51.  
  52. #endif    /* TIMER_STOP */
  53.  
  54.  
  55.